import { IsOptional, Validate } from 'class-validator';
import { UserHobby } from '@/enum';

export default class UpdateUserInfoDto {
  id: number;
  avatar: string;
  username: string;
  area: string;
  @IsOptional()
  @Validate((value: string) => {
    const values = value.split('|').map((item) => Number(item.trim()));

    const isValid = values.every((item) =>
      Object.values(UserHobby).includes(item),
    );
    if (!isValid) {
      throw new Error('偏好必须是 0:休闲 1:人文 2:现代 3:自然, 用 | 分割');
    }
  })
  hobby: string;
}
